package com.stx.blog.service.impl;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.BeanUtils;
import com.stx.blog.dao.BlogDao;
import com.stx.blog.entity.BlogEntity;
import com.stx.blog.service.BlogService;
import com.stx.blog.vo.BlogVo;
import com.sun.xml.internal.messaging.saaj.packaging.mime.util.BEncoderStream;

public class BlogServiceImpl implements BlogService {

	private BlogDao dao = null;

	@Override
	public List<BlogVo> list(BlogVo criteria) {
		List<BlogVo> voList = new ArrayList<BlogVo>();
		List<BlogEntity> entityList = dao.list(criteria);
		for (BlogEntity entity : entityList) {
			BlogVo vo = new BlogVo();
			BeanUtils.copyProperties(entity, vo);
			voList.add(vo);
		}
		return voList;
	}

	@Override
	public void addBlog(BlogVo blog) {
		dao.addBlog(blog);
	}

	@Override
	public void delBlog(Integer bid) {
		dao.delBlog(bid);
	}

	@Override
	public BlogVo BlogListByBid(Integer bid) {
		
		BlogVo blogVo=new BlogVo();
		BlogEntity blogEntity=dao.BlogListByBid(bid);
		BeanUtils.copyProperties(blogEntity, blogVo);
		return blogVo;
	}

	@Override
	public void updateBlog(BlogVo blog) {
		dao.updateBlog(blog);
	}
	
	public void setDao(BlogDao dao){
		this.dao=dao;
	}

}
